package com.vincent.template.controller.manage;

import com.vincent.template.commons.base.VctVo;
import com.vincent.template.dto.sys.uri.UriDto;
import com.vincent.template.service.logic.UriService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Vincent Wang
 * @date 2021/2/28 20:27
 */
@Api(tags = "uri管理")
@RestController
@RequestMapping("/manage/uri")
public class UriController {
    
    @Autowired
    private UriService uriService;

    @ApiOperation("查询所有uri")
    @GetMapping
    public List<UriDto> findUris() {
        return uriService.findUris();
    }

    @ApiOperation("根据id查询uri")
    @GetMapping("/{id}")
    public UriDto findUriById(@PathVariable("id") Long id) {
        return uriService.findUriById(id);
    }

    @ApiOperation("添加uri")
    @PostMapping("/create")
    public VctVo<Long> addUri(@Validated @RequestBody UriDto uriDto) {
        return VctVo.id(uriService.addUri(uriDto));
    }

    @ApiOperation("更新uri")
    @PutMapping("/{id}/update")
    public boolean updateUri(@PathVariable("id") Long id,
                             @Validated @RequestBody UriDto uriDto) {
        return uriService.updateUri(id, uriDto);
    }

    @ApiOperation("删除uri")
    @DeleteMapping("/{id}/delete")
    public boolean deleteUri(@PathVariable("id") Long id) {
        return uriService.deleteUri(id);
    }
}
